package cn.xsly.ymcc.service.impl;

import cn.xsly.ymcc.constants.Constants;
import cn.xsly.ymcc.domain.UserCode;
import cn.xsly.ymcc.mapper.UserCodeMapper;
import cn.xsly.ymcc.service.IUserCodeService;
import cn.xsly.ymcc.util.StrUtils;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author whale
 * @since 2022-10-30
 */
@Service
public class UserCodeServiceImpl extends ServiceImpl<UserCodeMapper, UserCode> implements IUserCodeService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public String loadUserCode() {
        String code = StrUtils.getRandomString(4);
        redisTemplate.opsForValue().set(Constants.INVITE_USER,code,30, TimeUnit.MINUTES);
        return code;
    }
}